package com.ruoyi.pachong;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.pachong.domain.HpageDaohang;
import com.ruoyi.pachong.domain.HpageNews;
import com.ruoyi.pachong.service.IHpageDaohangService;
import com.ruoyi.pachong.service.IHpageNewsService;
import com.ruoyi.pachong.service.impl.HpageNewsServiceImpl;

@RestController
@RequestMapping("${uriconfig.homepagepub}")
public class WebPaControlloer extends BaseController{
	
	private static final Logger log = LoggerFactory.getLogger(WebPaControlloer.class);
	@Autowired
    private IHpageNewsService  hpageNewsService; 
	
	@Autowired
    private IHpageDaohangService hpageDaohangService;
	
	@GetMapping("/hi")
    public AjaxResult hi()
    {
        //AjaxResult ajax = AjaxResult.success();
        System.out.println("hi~");
        
//        Long lastid = hpageNewsService.selectHpageLastNewId();
//        System.out.println("lastid:"+lastid);
//        HpageNews  hpnew = hpageNewsService.selectHpageNewsByNewId(lastid);
//        
//        HpageNews hp = new HpageNews();
//        hp.setNewUuid(hpnew.getNewUuid());
//        StopWatch stopWatch = new StopWatch();
//        stopWatch.start();
////        hpageNewsService.selectHpageNewsList(hp);
//        List<HpageNews>  newslist = hpageNewsService.selectHpageNewsList(hpnew.getNewUuid());
//        stopWatch.stop();
//        System.out.println("耗时计算1："+(double) stopWatch.getTime()/1000 + "s");
//        stopWatch.reset();
//        stopWatch.start();
//        Map<String, Map<String,List<HpageNews>>> groupByHpageNews = newslist.stream().sorted(Comparator.comparing(HpageNews::getClassOrder).thenComparing(HpageNews::getSubSiteOrder)).collect(Collectors.groupingBy(HpageNews::getClassName,LinkedHashMap::new,Collectors.groupingBy(HpageNews::getSubSiteName,LinkedHashMap::new, Collectors.toList())));
//        stopWatch.stop();
//        System.out.println("耗时计算2："+(double) stopWatch.getTime()/1000 + "s");
//        Map<String, Map<String,List<HpageNews>>> groupByHpageNews = newslist.stream().collect(Collectors.groupingBy(HpageNews::getClassName,Collectors.groupingBy(HpageNews::getSubSiteName)));
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        Map<String, Map<String,List<HpageNews>>> groupByHpageNews = hpageNewsService.selectHpageNewsList("");
        stopWatch.stop();
        System.out.println("耗时计算：hi():"+(double) stopWatch.getTime()/1000 + "s");
        log.info("耗时计算：查询新闻：hi():"+(double) stopWatch.getTime()/1000 + "s");
        //System.out.println(groupByHpageNews);
        
        //return AjaxResult.success(hpageNewsService.selectHpageNewsList(hp));
        return AjaxResult.success(groupByHpageNews);
    }
	
	@GetMapping("/hidaohang")
	public AjaxResult getDaoHang() {
		
		
		List<HpageDaohang> list = hpageDaohangService.selectHpageDaohangList(null);
		return AjaxResult.success(list);
	}

}
